package com.jesse.custom.component;

import com.jesse.main.R;
import com.wang.avi.AVLoadingIndicatorView;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;

public class CustomWatitingDialog extends ProgressDialog  {
	
	protected TextView alertText;
	protected String alertString = "";
	protected int indicatorType = AVLoadingIndicatorView.BallClipRotateMultiple;
	protected int indicatorColor = getContext().getResources().getColor(R.color.white);
	protected LinearLayout indicatorContent;
	protected AVLoadingIndicatorView indicator;
	
	public CustomWatitingDialog(Context context) {
		super(context);
	}
	
	public CustomWatitingDialog(Context context, String message){  
        super(context);  
        this.alertString = message;  
    }
	
	public CustomWatitingDialog(Context context, String message, boolean cancelable){  
        this(context, message, -1, -1, cancelable);
    }
	
	public CustomWatitingDialog(Context context, String message, int indicatorType, int color, boolean cancelable){  
        super(context);  
        this.alertString = message;  
        this.indicatorType = indicatorType;
        this.indicatorColor = color;
	}

	@Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.unit_waiting_dialog);  
        alertText = (TextView) findViewById(R.id.alertText);  
        alertText.setText(alertString); 
        indicatorContent = (LinearLayout) findViewById(R.id.indicatorContent);
        indicator = new AVLoadingIndicatorView(getContext());
        indicator.initStyle(indicatorType, indicatorColor);
        indicatorContent.addView(indicator);
    } 
	
	@Override
	public void dismiss() {
		if (indicator != null) {
			indicator.clearAnimation();
			indicator = null;
		}
		if (indicatorContent != null) {
			indicatorContent.removeAllViews();
			indicatorContent = null;
		}
		super.dismiss();
	}
}
